package com.example.auto.demoforleothon.View;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.auto.demoforleothon.Model.User;
import com.example.auto.demoforleothon.Presenter.UserLoginPresenter;
import com.example.auto.demoforleothon.R;
import com.example.auto.demoforleothon.base.BaseActivity;

public class MainActivity extends BaseActivity implements IuserLogin{

    EditText userName;
    EditText passWord;
    Button clear;
    Button login;
    private UserLoginPresenter userLoginPresenter=new UserLoginPresenter(this);

    @Override
    protected void initView() {
        super.initView();
        userName=findViewById(R.id.user_name);
        passWord=findViewById(R.id.password);
        clear=findViewById(R.id.clear);
        login=findViewById(R.id.login);

        clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                userLoginPresenter.clear();
            }
        });

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                userLoginPresenter.login();
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public String getUsername() {
        return userName.getText().toString();
    }

    @Override
    public String getPassword() {
        return passWord.getText().toString();
    }

    @Override
    public void clearUsername() {
        userName.setText("");
    }

    @Override
    public void clearPassword() {
        passWord.setText("");
    }

    @Override
    public void toMainActivity(User user) {
        Toast.makeText(MainActivity.this,"跳转主页面",Toast.LENGTH_SHORT).show();
        Intent i=new Intent(MainActivity.this,TestLogin.class);
        startActivity(i);
    }

    @Override
    public void showErrorInfo() {
        Toast.makeText(MainActivity.this,"登录出错",Toast.LENGTH_SHORT).show();
    }
}
